using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CR.Domain.Entities;

namespace CR.Infrastructure.Repositories
{
    /// <summary>
    /// 溯源管理仓储接口
    /// </summary>
    public interface ITraceabilityRepository : IBaseRepository<TraceabilityManagement>
    {
        /// <summary>
        /// 根据溯源码获取溯源管理信息
        /// </summary>
        /// <param name="traceabilityCode">溯源码</param>
        /// <returns>溯源管理信息</returns>
        Task<TraceabilityManagement> GetByTraceabilityCodeAsync(string traceabilityCode);

        /// <summary>
        /// 检查溯源码是否已存在
        /// </summary>
        /// <param name="traceabilityCode">溯源码</param>
        /// <returns>是否已存在</returns>
        Task<bool> ExistsTraceabilityCodeAsync(string traceabilityCode);

        /// <summary>
        /// 获取所有未删除的溯源管理记录
        /// </summary>
        /// <returns>未删除的溯源管理记录列表</returns>
        Task<IEnumerable<TraceabilityManagement>> GetAllActiveAsync();

        /// <summary>
        /// 高级查询，分页获取溯源管理信息
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="productName">商品名称（可选）</param>
        /// <param name="productionBatchStart">生产批次开始日期（可选）</param>
        /// <param name="productionBatchEnd">生产批次结束日期（可选）</param>
        /// <param name="shelfLifeMin">最小保质期天数（可选）</param>
        /// <param name="shelfLifeMax">最大保质期天数（可选）</param>
        /// <param name="productionLicenseNumber">生产许可证号（可选）</param>
        /// <param name="productionCompany">生产企业（可选）</param>
        /// <returns>分页结果</returns>
        Task<(IEnumerable<TraceabilityManagement> Data, int Total)> GetPagedTraceabilityAsync(
            int pageIndex,
            int pageSize,
            string productName = null,
            DateTime? productionBatchStart = null,
            DateTime? productionBatchEnd = null,
            int? shelfLifeMin = null,
            int? shelfLifeMax = null,
            string productionLicenseNumber = null,
            string productionCompany = null);

        /// <summary>
        /// 批量删除溯源管理信息（逻辑删除）
        /// </summary>
        /// <param name="ids">ID列表</param>
        /// <returns>操作结果</returns>
        Task<bool> BatchDeleteAsync(IEnumerable<int> ids);

        /// <summary>
        /// 更新完善度评分
        /// </summary>
        /// <param name="id">溯源管理ID</param>
        /// <param name="score">完善度评分</param>
        /// <returns>操作结果</returns>
        Task<bool> UpdateCompletenessScoreAsync(int id, int score);
    }
} 